package com.juyu.miliao.scheduler.service;

import com.juyu.miliao.scheduler.dao.mysql.LabelDao;
import com.juyu.miliao.scheduler.domin.Label;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LabelService {
    @Resource
    private LabelDao labelDao;
    @Resource
    private LabelCacheService labelCacheService;

    public List<Label> getLabelCountByUserId(Long userId) {
        List<Label> list = labelDao.getUserMeLabelByUserId(userId);
        list.forEach(i->i.setLabelName(getLabelName(i.getLabelId())));
        return list;
    }

    //获取标签名称
    public String getLabelName(Long labelId){
        Map<Long, Label> map = new HashMap<>();
        List<Label> labelList = labelCacheService.getLabelList();
        for(Label entity:labelList){
            map.put(entity.getLabelId(), entity);
        }
        return map.get(labelId).getLabelName();
    }

}
